<?php

namespace mpend\modules\home\models;

use common\models\actor\Actor;
use Yii;
use common\logics\PositionLogic;
use common\models\shop\ShopChannel;
use common\helpers\Url;
use common\models\base\NavigationItem;

/**
 * 首页默认面板信息
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class HomeDashboardLogic extends \common\logics\DashboardLogic {

    /**
     * @var array 轮播图
     */
    public $broadcast = [];

    /**
     * @var array 系统通知
     */
    public $notice = [];

    /**
     * @var array 推荐伙伴
     */
    public $recommenders;

    /**
     * @var array 推荐贡献值
     */
    public $devoters;

    /**
     * @var array 猜你喜欢
     */
    public $thinks;

    /**
     * 顶部轮播图
     */
    protected function setBroadcast() {
        return PositionLogic::current('shop.home.broadcast', []);
    }

    /**
     * 通知消息
     */
    protected function setNotice() {
        return [
            'icon' => Url::attach('assets/contribute/arrow_right.png'),
            'thumb' => Url::attach('assets/contribute/contribute_icon.png'),
            'text' => '我要上首页！',
            'description' => '查看贡献值',
            'link' => ''
        ];
    }

    /**
     * 根据数据分析得到的四个推荐人
     */
    protected function setRecommenders() {
        $model = new RecommendSearch();
        $model->user_id = $this->uid;
        return $model->recommenders(4);
    }

    /**
     * 贡献值高的返回8个
     */
    protected function setDevoters() {
        $query = Actor::find()->alias('t')->active();
        $query->orderBy('weight');
        $query->limit(8);
        return $query->all();
    }

    /**
     * 猜你喜欢
     */
    protected function setThinks() {
        $model = new ThinksSearch();
        $model->user_id = $this->uid;
        return $model->recommenders(4);
    }

}
